package qmlt.learning.decisiontree.control;

import qmlt.learning.decisiontree.DecisionTree;
import qmlt.learning.decisiontree.Node;

public class DecisionTreeController
{
    private TreeBuildController treeBuildController;

    private PruneController     pruneController;

    public DecisionTreeController(TreeBuildController treeBuildController,
            PruneController pruneController)
    {
        this.treeBuildController = treeBuildController;
        this.pruneController = pruneController;
    }

    public void split(Node node)
    {
        treeBuildController.split(node);
    }

    public void prune(DecisionTree tree)
    {
        if (pruneController != null)
            pruneController.prune(tree);
    }
    
    public String toString()
    {
    	StringBuilder sb = new StringBuilder();
    	
    	if (treeBuildController instanceof InfoGainTreeBuildController)
    	{
    		sb.append("info-gain");
    	}
    	else if (treeBuildController instanceof GainRatioTreeBuildController)
    	{
    		sb.append("gain-ratio");
    	}
    	else
    	{
    		sb.append(treeBuildController.toString());
    	}
    	sb.append("/");
    	if (pruneController instanceof ReducedErrorPruner)
    	{
    		sb.append("reduced-error");
    	}
    	else if (pruneController instanceof PessimisticPruner)
    	{
    		sb.append("pessimistic");
    	}
    	else
    	{
    		sb.append(pruneController.toString());
    	}
    	
    	return sb.toString();
    }
}
